<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
session_start();

class todo extends CI_Controller {

    public function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in_user')) {
            $this->logged_in = TRUE;
        } else {
            redirect('login/', 'refresh');
        }
        $this->load->model('Dao');
        $this->load->helper('date');
    }

    public function index() {
        $data = array('user' => $this->session->userdata('logged_in_user'));
        $data['title'] = 'Welcome to wfaces';
        $data['description'] = 'NONE';
        $data['keywords'] = 'Key, words, of, the, page';
        $data['todos'] = $this->Dao->findTodos();
        $data['view'] = 'v_todo';

        $this->load->view('templates/template', $data);
    }

    public function insert() {
        $text = $this->input->post('todoText');
        $data = array(
            'id' => '',
            'todo_text' => $text,
            'dt_insertion' => date('Y-m-d H:i:s', now()),
            'dt_done' => null
        );
        $this->Dao->insertTodo($data);
        redirect('todo/', 'refresh');
    }

    public function Done($id) {
        $this->Dao->updateToDone($id);
        redirect('todo/', 'refresh');
    }

    public function sc() {
        $this->load->view('scrollTest');
    }

}

?>
